<?php
session_start();

include "webmaster_connect.php";

$page_permission = 2;

include "webmaster_check_login.php";
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style type="text/css">
body {
	background-image: url(../images/wood.jpg);
	background-repeat: repeat-x;
	margin: 0px;
	background-position: left top;
	background-attachment: fixed;
	background-color: #000000;
	padding-top: 0px;
	padding-right: 0px;
	padding-bottom: 0px;
	padding-left: 0px;
}
</style>
<link href="../css/webmaster_guest_alerts.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="page_container">

<?php 

include "../admin_files/webmaster_header.php";
include "../admin_files/webmaster_navigation.php" 

?>

<div id="content_container">


<h1>Guest alerts:</h1>

<form id="date_filter" action="webmaster_customer_messages.php" method="post" name="date_filter">

<label> Message status: 
<select name="message_status">
<option value="New">New</option>
<option value="Read">Read</option>
<option value="All">All</option>
</select>
</label>

<input name="refresh_messages" type="submit" value="Refresh" />

</form>

<table width="970px" border="0" cellpadding="3">

<tr>
    <th class="header" scope="col"></th>
    <th class="header" scope="col">Status</th>
    <th class="header" scope="col">product_id</th>
    <th class="header" scope="col">Customer name</th>
    <th class="header" scope="col">Customer email</th>
    <th class="header" scope="col">Date</th>
  </tr>

<?php 
 
$message_filter = $_POST['message_status'];
 
$query = "SELECT *
		  FROM customer_messages";

if(isset($_POST['message_status'])) //If status is posted then do below checks

{

	if ($message_filter != "All") //If filter selected is NOT "All"

	{
		$query .= ' WHERE message_status = "'.$_POST['message_status'].'"';
	}
	
}

if(!isset($_POST['message_status'])){$query.= ' WHERE message_status = "New"';}
		  
$query .= " ORDER BY id DESC";

$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
	
	$message_date = $row['date'];
	$message_date = date("d/m/Y", strtotime($message_date));
	$id = $row['id'];
	
echo '

  <tr id="'.$row['id'].'">
	<th>
		<form action="webmaster_view_customer_message.php" method="post" name="read_message">
		<input name="id" type="hidden" value="'.$id.'" />
		<input name="read_message" type="submit" value="Read" />
		</form>
		
		<form action="webmaster_process_delete_customer_mesage.php" method="post" name="delete_message">
		<input name="id" type="hidden" value="'.$id.'" />
		<input name="delete_message" type="submit" value="Delete" />
		</form>
	</th>
	<th>'.$row['message_status'].'</th>
	<th>'.$row['product_id'].'</th>
	<th>'.$row['customer_name'].'</th>
	<th>'.$row['customer_email'].'</th>
	<th>'.$message_date.'</th>
  </tr>

';
	
}


?>

</table>

<?php
/////////////////////////
//TESTING - Display query
/////////////////////////

//echo $query 

/////////////
//END Testing
/////////////

?>

</div>
<!--login_container-->

</div> 
<!--page_container-->

</body>
</html>

